<?php

namespace app\admin\controller;

require EXTEND_PATH . 'qiniu-sdk/autoload.php';

use Qiniu\Auth;
use think\Db;

class Upload extends Base
{
    public function getUpToken()
    {
        // 用于签名的公钥和私钥
        $accessKey = config('qiniu.ACCESSKEY');
        $secretKey = config('qiniu.SECRETKEY');
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);

        $bucket = config('qiniu.BUCKET');

        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        $time = intval(time());
        $this->suc(['uptoken' => $token, 'time' => $time]);

    }

    public function getUpTokenString()
    {
        // 用于签名的公钥和私钥
        $accessKey = config('qiniu.ACCESSKEY');
        $secretKey = config('qiniu.SECRETKEY');
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);

        $bucket = config('qiniu.BUCKET');

        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        exit(json_encode(["uptoken" => $token]));

    }

}